package com.etlmaster.util.vfs;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public class VfsServer {
	
	private String scheme;
	private String host;
	private String port;
	private String user;
	private String pwd;
	
	public VfsServer(String scheme, String host, String port, String user,String pwd) {
		super();
		this.scheme = scheme;
		this.host = host;
		this.port = port;
		this.user = user;
		this.pwd = pwd;
	}

	@Override
	public String toString(){
		return builderServer();
	}
	
	public String builderServer(){
		StringBuilder sb = new StringBuilder();
		sb.append(scheme).append("://").append(builderAuthInfo()).append(host).append(":").append(port);
		return sb.toString();
	}
	
	private String builderAuthInfo(){
		if(user!=null && user.length()>0){
			StringBuilder sb = new StringBuilder();
			try {
				sb.append(user).append(":").append(URLEncoder.encode(pwd,"UTF-8")).append("@");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			return sb.toString();
		}
		return "";
	}
	
	public String getScheme() {
		return scheme;
	}

	public void setScheme(String scheme) {
		this.scheme = scheme;
	}

	public String getHost() {
		return host;
	}
	
	public void setHost(String host) {
		this.host = host;
	}
	
	public String getPort() {
		return port;
	}
	
	public void setPort(String port) {
		this.port = port;
	}
	
	public String getUser() {
		return user;
	}
	
	public void setUser(String user) {
		this.user = user;
	}
	
	public String getPwd() {
		return pwd;
	}
	
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

}
